package com.sky.web.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sky.domain.Book;
import com.sky.exception.BookException;
import com.sky.service.BookService;

public class DeleteBookByBatchServlet extends HttpServlet {



	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取请求参数
		//ids内容是把多个字符串用逗号隔开	
		String ids =  request.getParameter("ids");
		//ids处理成数组 1
		String[] idArray= ids.split(",");
		
		
		//处理业务逻辑，调用service
		BookService bookService =new BookService();
		try {
			bookService.DelBybatch(idArray);
		    //删除成功！继续查询剩余数据并在列表页面显示
			List<Book> list = bookService.queryBookList();
			request.setAttribute("booklist",list );
			request.getRequestDispatcher("product/list.jsp").forward(request, response);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			//删除失败
			request.setAttribute("del_msg", e.getMessage());
			request.getRequestDispatcher("product/list.jsp").forward(request, response);
		} catch (BookException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			//删除失败
			request.setAttribute("del_msg", e.getMessage());
			request.getRequestDispatcher("product/list.jsp").forward(request, response);
		}
	
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

	

}
